package com.freemodbus4j.device.storage;

import java.util.HashMap;
import java.util.Map;

public final class DeviceManager {

    private final Map<Short, Device> DEVICE_MAP = new HashMap<>();

    private static volatile DeviceManager DEVICEMANAGER = null;

    public static DeviceManager newInstance() {
        if (DEVICEMANAGER == null) {
            synchronized (DeviceManager.class) {
                if (DEVICEMANAGER == null) {
                    DEVICEMANAGER = new DeviceManager();
                }
            }
        }
        return DEVICEMANAGER;
    }

    public void put(Short deviceId, Device device) {
        this.DEVICE_MAP.put(deviceId, device);
    }

    public Device get(Short deviceId) {
        return this.DEVICE_MAP.get(deviceId);
    }
}
